using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class PropInfo
{
    public int percent;
    public GameObject prefab;
}

public class PropManager : Singleton<PropManager>
{
    [SerializeField] private List<PropInfo> percentList = new List<PropInfo>();

    protected override void Awake()
    {
        base.Awake();
    }

    private void OnEnable() {
        EventHandler.AddListener<Transform>(Events.SpawnProp, SpawnProp);
    }
    
    private void OnDisable() {
        EventHandler.RemoveListener(Events.SpawnProp);
    }

    private void SpawnProp(Transform tf)
    {
        for(int i=0; i<percentList.Count; i++)
        {
            int percent = percentList[i].percent;
            GameObject prefab = percentList[i].prefab;

            if(Random.Range(0, 100) <= percent)
            {
                // Instantiate(prefab, tf.position, Quaternion.identity);
                GameObject go = PoolManager.Instance.ReuseGO(prefab, tf.position, Quaternion.identity);
                break;
            }
        }
    }
}
